﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HR60_PanelSoft.View.Base;
using HR60_PanelSoft.View.TabForms.ListItems;
using HR60_PanelSoft.Model;
using HR60_PanelSoft.Model.BaseModel;

namespace HR60_PanelSoft.View.TabForms
{
	public partial class PanelForm_Signal : BaseForm
	{
		public PanelForm_Signal()
		{
			InitializeComponent();

			// 外部信号定义列表
			IDictionary  sconstMap = new Dictionary<string, SignalConst>();
			sconstMap.Add("未定义", SignalConst.NULL);
			sconstMap.Add("常开", SignalConst.OPEN);
			sconstMap.Add("常闭", SignalConst.CLOSE);
			selSconst.bindData(sconstMap);

			// 关联亮度列表
			IDictionary brightnessMap = new Dictionary<string, int>();
			for (int i = 1; i <= 7; i++)
			{
				brightnessMap.Add("亮度" + i, i);
			}
			selBrightness.bindData(brightnessMap);
		}

		// 绑定数据
		public override void refreshFormData(System.Collections.Generic.IDictionary<string, object> dataMap)
		{
			HR60_PanelSoft.Model.Panel panel = (HR60_PanelSoft.Model.Panel)dataMap["panel"];

			selScene.Value = panel.signal.sconst;
			selBrightness.Value = panel.signal.brightness;
			txtDelay.Value = panel.signal.delay;

			// 场景列表
			selScene.cleanItems();
			selScene.bindData((IList)scenes, "name", "uuid");
			if (panel.signal.scene != null)
			{
				radioScene.Checked = true;
				selScene.Value = panel.signal.scene;
			}

			// 负载设备列表
			sceneDeviceList.init(panel);
			sceneDeviceList.DeviceEventChange += new HR60_PanelSoft.View.TabForms.Handles.DeviceEventChangeHandle(sceneDeviceList_DeviceEventChange);

			if (panel.signal.scene == null)
			{
				radioScene.Checked = true;
			}
			else
			{
				radioDevice.Checked = true;
			}
		}

		// 场景事件更改
		void sceneDeviceList_DeviceEventChange(Device tagDevice, SceneEvent sceneEvent)
		{
			// TODO:
		}

		// 数据修改事件，基础信息
		public override void onFormChanged(BaseFormControl sender, System.EventArgs e)
		{
			// TODO:
		}

		private void checkedChanged(object sender, EventArgs e)
		{
			divScene.Visible = radioScene.Checked;
			divDevice.Visible = radioDevice.Checked;
		}
	}
}
